fix(snowflake/ast): generated walker skipped all non-Node helper-struct fields (SELECT targets, CTEs, CASE whens, OVER, MERGE whens, ...)#294
Merged
Conversation
…xpr.Whens, FuncCallExpr.Over/OrderBy, ...) — genwalker recursion The generated walker only handled Node / []Node / [][]Node / *NodeStruct fields, silently skipping every other node-bearing shape. ast.Inspect/Walk therefore never reached: - non-Node helper structs (CaseExpr.Whens []*WhenClause, FuncCallExpr.Over *WindowSpec, FuncCallExpr.OrderBy []*OrderItem, SelectStmt.With []*CTE / Targets []*SelectTarget / GroupBy / OrderBy / Fetch, UpdateStmt.Sets, MergeStmt.Whens, InsertMultiStmt.Branches, SetStmt.Vars, JsonLiteralExpr.Pairs, TableConstraint.References, ColumnDef helpers, CloneSource, ViewColumn, RowAccessPolicy, AlterTableAction, ...) - slices of pointers to Node structs ([]*ColumnDef, []*ObjectName, []*CopyOption, []*TypeName, []*PivotValue, []*UnpivotColumn, ...) - by-value Node structs (FuncCallExpr.Name ObjectName) This broke column collection in every walker consumer — analysis query-span lost CASE WHEN/THEN and OVER (PARTITION BY / ORDER BY) columns, and the advisor never saw CTE bodies or SELECT-list subqueries. Same bug class as the googlesql CompareExpr walk gap (#274). genwalker now classifies all node-bearing field shapes, emits one walk<T> function per node-bearing non-Node helper struct (fixpoint over nested helpers, e.g. WindowSpec -> WindowFrame -> WindowBound), walks []*T node slices and by-value Node fields, and fails generation loudly if a node-bearing field has an unsupported shape so the gap cannot silently reopen. Output stays deterministic and gofmt-clean (148 cases, 447 child fields, 25 helper walkers). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
snowflake/astgenerated walker silently skipped every Node-bearing field whose type is a non-Node helper struct —ast.Walk/Inspectnever reached them. The audit (throwaway AST analyzer, cross-checked against the generated file) found this covered far more than the reported symptom:SelectStmt.Targets(the whole SELECT list),SelectStmt.With(CTE bodies),CaseExpr.Whens,FuncCallExpr.Over/OrderBy,MergeStmt.Whens,UpdateStmt.Sets,CreateTableStmt.Columns/Constraints, AlterTable actions, and ~30 statements' Options/Tags lists — 25 node-bearing helper structs total.genwalker change
Full shape classifier + fixpoint computation of node-bearing helpers (handles nesting WindowSpec→WindowFrame→WindowBound); emits one nil-safe
walk<Helper>per helper; fatal guard — any node-bearing field in an unrecognized shape now fails generation instead of silently skipping (prevents recurrence). Output: 141→148 cases, 287→447 child fields, 25 helper walkers; deterministic; gofmt-clean.Found by
Codex cross-review of the bytebase snowflake cutover (CASE/window lineage came back empty in the migrated query-span extractor). Same bug class as the googlesql CompareExpr walk gap (#274).
Tests
walk_coverage_test.go(31 subtests on real SQL — all fail on the old walker) + 3analysis/query_spantests proving CASE/window/WITHIN-GROUP columns are now attributed (previously lost). Fullgo test ./snowflake/... -count=1green incl. corpus; deparse unaffected. Orchestrator independently verified on a fresh checkout of1f14ee92: build/vet/gofmt clean, regen byte-identical, full suite green.Cross-engine audit (report only, this PR fixes snowflake)
[][]ExprNodenever walked →InsertStmt.Values/ValuesStmt.Rowsinvisible to Walk/Inspect.CreateForeignTableStmt.Base CreateStmtunreachable.🤖 Generated with Claude Code